{extend name="public/base" /}
{block name="content"}
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-home"></i>&nbsp;文章管理
            </li>
            <li>文章列表</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Body -->
    <div class="page-body">
        <a href="{:url('admin/article/articleadd')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
        <div class="row">
            <div class="col-xs-12">
                <div class="widget">
                    <div class="widget-header">
                        <span class="widget-caption">文章列表</span>
                        <div class="widget-buttons">
                            {$articles->render()|raw|replace}
                        </div>
                    </div>
                    <div class="widget-body">
                        <table class="table table-hover table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>文章标题</th>
                                <th>作者</th>
                                <th>所属导航</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            {volist name="articles" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.title}</td>
                                <td>{$vo.author}</td>
                                <td>{$vo.cate.catename}</td>
                                <td>
                                    {if $vo.aup == 1}
                                    <a href="#" class="btn btn-sm btn-azure articleUp" dataid="{$vo.id}" dataup="{$vo.aup}">取消置顶</a>
                                    {else /}
                                    <a href="#" class="btn btn-sm btn-success articleUp" dataid="{$vo.id}" dataup="{$vo.aup}">置顶</a>
                                    {/if}
                                    <a href="{:url('admin/article/articleedit', ['id' => $vo.id])}" class="btn btn-sm btn-warning">编辑</a>
                                    <a href="#" class="btn btn-sm btn-danger articleDel" dataid="{$vo.id}">删除</a>
                                </td>
                            </tr>
                            {/volist}
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /Page Body -->
</div>
{/block}
{block name="js"}
{__block__}
<script>
    $(function () {
       $('.pagination').addClass('pagination-sm');

       $('.articleUp').click(function () {
           var id = $(this).attr('dataid');
           var aup = $(this).attr('dataup');
           if (aup == 1) {
               var msg = '确定取消置顶吗？';
           }else {
               var msg = '确定置顶吗？';
           }
           layer.confirm(msg, {
               title:'置顶操作',
               icon:3,
               anim:6
           }, function (index) {
               layer.close(index);
               $.ajax({
                   url:"{:url('admin/article/articleUp')}",
                   type:'post',
                   data:{id:id, aup:aup},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1) {
                           layer.msg(data.msg, {
                               icon:6,
                               time:2000
                           }, function () {
                               location.href = data.url;
                           });
                       }else {
                           layer.open({
                               title:'置顶操作失败',
                               content:data.msg,
                               icon:5,
                               anim:6
                           });
                       }
                   }
               });
           });
           return false;
       });

       $('.articleDel').click(function () {
           var id = $(this).attr('dataid');
           layer.confirm('确定删除吗？', {
               title:'删除文章',
               icon:3,
               anim:6
           }, function (index) {
               layer.close(index);
               $.ajax({
                   url:"{:url('admin/article/articledel')}",
                   type:'post',
                   data:{id:id},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1) {
                           layer.msg(data.msg, {
                               icon:6,
                               time:2000
                           }, function () {
                               location.href = data.url;
                           });
                       }else {
                           layer.open({
                               title:'文章编辑失败',
                               content:data.msg,
                               icon:5,
                               anim:6
                           });
                       }
                   }
               });
           });
           return false;
       });
    });
</script>
{/block}